<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - threaded_object_extension.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2007  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_THREADED_OBJECT_EXTENSIOn_CPP
<font color='#0000FF'>#define</font> DLIB_THREADED_OBJECT_EXTENSIOn_CPP

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='threaded_object_extension.h.html'>threaded_object_extension.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='create_new_thread_extension.h.html'>create_new_thread_extension.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    threaded_object::
    <b><a name='threaded_object'></a>threaded_object</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>:
        s<font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>,
        id1<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        is_running_<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        is_alive_<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        should_stop_<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        id_valid<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
    <b>{</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    threaded_object::
    ~<b><a name='threaded_object'></a>threaded_object</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>try</font>
        <b>{</b>
            <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_alive</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
                   "<font color='#CC0000'>\tthreaded_object::~threaded_object()</font>"
                   <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou have let a threaded object destruct itself before terminating its thread</font>"
                   <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
            <font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>std::exception<font color='#5555FF'>&amp;</font> e<font face='Lucida Console'>)</font>
        <b>{</b>
            std::cerr <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> e.<font color='#BB00BB'>what</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> std::endl;
            <font color='#BB00BB'>assert</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>abort</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> threaded_object::
    <b><a name='is_running'></a>is_running</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tbool threaded_object::is_running()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> is_running_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> threaded_object::
    <b><a name='is_alive'></a>is_alive</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tbool threaded_object::is_alive()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> is_alive_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> threaded_object::
    <b><a name='wait'></a>wait</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tvoid threaded_object::wait()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>is_alive_<font face='Lucida Console'>)</font>
            s.<font color='#BB00BB'>wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> threaded_object::
    <b><a name='start'></a>start</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tvoid threaded_object::start()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_alive_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>create_new_thread<font color='#5555FF'>&lt;</font>threaded_object,<font color='#5555FF'>&amp;</font>threaded_object::thread_helper<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                is_running_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                <font color='#0000FF'>throw</font> <font color='#BB00BB'>thread_error</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        is_alive_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        is_running_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        should_stop_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        s.<font color='#BB00BB'>broadcast</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> threaded_object::
    <b><a name='restart'></a>restart</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tvoid threaded_object::restart()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_alive_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>create_new_thread<font color='#5555FF'>&lt;</font>threaded_object,<font color='#5555FF'>&amp;</font>threaded_object::thread_helper<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                is_running_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                <font color='#0000FF'>throw</font> <font color='#BB00BB'>thread_error</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            should_respawn_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            should_respawn_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        <b>}</b>
        is_alive_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        is_running_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        should_stop_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        s.<font color='#BB00BB'>broadcast</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> threaded_object::
    <b><a name='set_respawn'></a>set_respawn</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tvoid threaded_object::set_respawn()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        should_respawn_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> threaded_object::
    <b><a name='should_respawn'></a>should_respawn</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tbool threaded_object::should_respawn()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> should_respawn_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> threaded_object::
    <b><a name='pause'></a>pause</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tvoid threaded_object::pause()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        is_running_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> threaded_object::
    <b><a name='stop'></a>stop</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>id1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
               "<font color='#CC0000'>\tvoid threaded_object::stop()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can NOT call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        should_stop_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        is_running_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        should_respawn_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        s.<font color='#BB00BB'>broadcast</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> threaded_object::
    <b><a name='should_stop'></a>should_stop</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>is_alive_ <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> id1 <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> id_valid <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font>,
               "<font color='#CC0000'>\tbool threaded_object::should_stop()</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou can only call this function from the thread that executes threaded_object::thread</font>"
               <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>is_running_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> should_stop_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            s.<font color='#BB00BB'>wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> should_stop_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> threaded_object::
    <b><a name='thread_helper'></a>thread_helper</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
<font color='#0000FF'>#ifdef</font> ENABLE_ASSERTS
        id1 <font color='#5555FF'>=</font> <font color='#BB00BB'>get_thread_id</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        id_valid <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
<font color='#0000FF'>#endif</font>
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font>
        <b>{</b>
            m_.<font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            should_respawn_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            m_.<font color='#BB00BB'>unlock</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>thread</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m_<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>should_respawn_<font face='Lucida Console'>)</font>
                <font color='#0000FF'>continue</font>;

<font color='#0000FF'>#ifdef</font> ENABLE_ASSERTS
            id_valid <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
<font color='#0000FF'>#endif</font>

            is_alive_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            is_running_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            should_stop_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            s.<font color='#BB00BB'>broadcast</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>return</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_THREADED_OBJECT_EXTENSIOn_CPP
</font>

</pre></body></html>